package org.hishen.example.web.admin.mall;

import javax.annotation.Resource;

import org.hishen.example.entity.mall.Goods;
import org.hishen.example.service.admin.mall.GoodsService;
import org.hishenframework.data.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Goods控制类
 * @author 您的大名
 *
 */
@Controller
@RequestMapping(GoodsController.PATH)
public class GoodsController {

	public static final String PATH = "/admin/mall/goods";
	public static final String RELOAD = "redircet:" + PATH;
	
	@Resource
	private GoodsService goodsService;
	
	/**
	 * 列表
	 * @param page
	 * @param model
	 * @return
	 */
	@RequestMapping
	public String list(Page page, Model model) {
		goodsService.list(page, "g", 1, 200);
		return PATH + "/list";
	}

	/**
	 * 创建
	 */
	@RequestMapping("/create")
	public void create() {
	}
	
	/**
	 * 保存
	 * @param goods
	 */
	@RequestMapping(value = "/save")
	public void save(Goods goods) {
		goodsService.save(goods);
	}
	
	/**
	 * 获取一个Goods
	 * @param id
	 * @param model
	 */
	@RequestMapping("/edit/{id}")
	public void edit(@PathVariable int id, Model model) {
		model.addAttribute(goodsService.get(id));
	}
	
	/**
	 * 更新
	 * @param goods
	 */
	@RequestMapping("/update")
	public void update(Goods goods) {
		goodsService.update(goods);
	}
	
	/**
	 * 删除
	 * @param goods
	 */
	@RequestMapping("/delete")
	public void delete(Goods[] goods) {
		goodsService.delete(goods);
	}
	
}
